/*
 * Copyright (C) 2017 ~ 2019 Deepin Technology Co., Ltd.
 *
 * Author:     zhangbingyi <zhangbingyi@uniontech.com>
 *
 * Maintainer: zhangbingyi <zhangbingyi@uniontech.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#pragma once

#include "common/defenderprocinfolist.h"
#include "csingleteon.h"
#include "common.h"

#include <QObject>
#include <QMap>

#define Work_Speed_Debug 0
#define Work_Flow_Debug 0

// 安卓应用包名开头部分
#define UENGINE_APP_PKG_NAME_HEAD "uengine."

namespace def {
class SystemSettings;
}

class SettingsInvokerInterface;
class DBusInvokerInterface;

using namespace def;

class DataUsageModel : public QObject
{
    Q_OBJECT
public:
    explicit DataUsageModel(QObject *parent = nullptr);

    // 将speedwidget中的DBUS、GSETTINGS调用移到此处
    QString GetNetControlAppStatus() const;
    bool GetDataUsageSwitchStatus() const;
    void SetNetAppStatusChange(const QString &, int) const;
    void AddSecurityLog(const QString &) const;

    DefenderProcInfoList getProcInfoList() const;
    // 异步方式获取某个app流量数据
    void asyncGetAppFlowList(const QString &pkgName, const TimeRangeType &timeRangeType);
    // 异步方式获取所有app流量数据
    void asyncGetAllAppFlowList(const TimeRangeType &timeRangeType);

    // 获取资源管控服务状态（true-可行，false-失效）
    bool getUosResourceStatus();

Q_SIGNALS:
    void sendProcInfoList(const DefenderProcInfoList &procInfos);
    // 向应用流量详情对话框实例发送显示的数据列表
    void sendAppFlowList(const QString &pkgName, const int timeRangeType, const DefenderProcInfoList &flowLst);
    // 发送来自服务的流量排名应用数据
    void sendAllAppFlowList(const int timeRangeType, const DefenderProcInfoList &flowLst);

public Q_SLOTS:
    void recProcInfoList(const DefenderProcInfoList &procInfos);
    void recAllppFlowList(const int timeRangeType, const DefenderProcInfoList &flowLst);
    void recAppFlowList(const QString &pkgName, const int timeRangeType, const DefenderProcInfoList &flowLst);

private:
    QString getAppNameFromDesktop(const QString &desktopPath);

private:
    SystemSettings *m_sysSettings;
    DBusInvokerInterface *m_monitorInterFaceServer;
    DBusInvokerInterface *m_dataInterFaceServer;
    SettingsInvokerInterface *m_gsNetControl;
    DefenderProcInfoList m_procInfoList;
};

